package com.example.project_springboot.service.impl;

import com.example.project_springboot.aop.Log;
import com.example.project_springboot.mapper.EmpMapper;
import com.example.project_springboot.pojo.Emp;
import com.example.project_springboot.pojo.PageBean;
import com.example.project_springboot.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
//@Scope("prototype")//scope配置作用域 prototype创建不同的bean对象 singleton默认单例模式
//@Lazy //延迟初始化相当于懒汉式创建方式
public class EmpServiceImpl implements EmpService {
    @Autowired
    EmpMapper empMapper;
    @Override
    public void deleteEmp(Long[] ids) {
        empMapper.deleteEmp(ids);
    }

    @Override
    public PageBean selectEmp(Integer page, Integer pageSize, String name, Short gender, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page,pageSize);
       List<Emp> emps =  empMapper.selectEmp(name,gender,begin,end);
        Page<Emp> p = (Page<Emp>) emps;
        return new PageBean(p.getTotal(),p.getResult());
    }

    @Override
    public Emp getById(Integer id) {
        return empMapper.getById(id);
    }

    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {
        return empMapper.psdAndusername(emp);
    }
}
